package com.mz.ozy.adapter;

import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.ReportBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/3/29.
 */

public class ReportAdapter extends BaseQuickAdapter<ReportBean, BaseViewHolder> {


    public ReportAdapter(List<ReportBean> data) {
        super(R.layout.item_report_info, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final ReportBean item) {
        helper.setText(R.id.tv_report_reason, item.getReason());

        final ImageView imgSelect = helper.getView(R.id.tv_report_select);
        if (item.isSelect()) {
            imgSelect.setImageResource(R.mipmap.report_select_icon);
        } else {
            imgSelect.setImageResource(R.mipmap.report_unselect_icon);
        }

        imgSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.isSelect()) {
                    imgSelect.setImageResource(R.mipmap.report_unselect_icon);
                    item.setSelect(false);
                } else {
                    imgSelect.setImageResource(R.mipmap.report_select_icon);
                    item.setSelect(true);
                }
            }
        });
    }

    public List<String> getSelectReason() {
        List<String> list = new ArrayList<>();
        for (ReportBean bean : getData()) {
            if (bean.isSelect()) {
                list.add(bean.getReason());
            }
        }
        return list;
    }
}
